﻿using System.ComponentModel;
using Loki.Data;

namespace Loki.Engine
{
    public abstract class AtomicEntity<TEntityKey, TModelType> : Entity<TModelType>, IAtomicEntity<TEntityKey>
    {
        #region  ID
        private static PropertyChangedEventArgs _IDChangeArgs = ObservableHelper.CreateArgs<AtomicEntity<TEntityKey, TModelType>>(x => x.ID);

        private TEntityKey _ID;

        public TEntityKey ID
        {
            get
            {
                return _ID;
            }

            set
            {
                if (!object.Equals(value, _ID))
                {
                    _ID = value;
                    NotifyChangedAndDirty(_IDChangeArgs);
                }
            }
        }
        #endregion

        public AtomicEntity()
            : base()
        {
        }

        public AtomicEntity(AtomicEntity<TEntityKey, TModelType> P_Clone)
            : base(P_Clone)
        {
            _ID = P_Clone.ID;
        }

        public AtomicEntity(IAtomicEntity<TEntityKey> P_Clone)
        {
            ID = P_Clone.ID;
        }

        public AtomicEntity(IDataEntity<TEntityKey> P_Clone)
            : base()
        {
            _ID = P_Clone.PK;
        }
    }
}
